﻿using System;

namespace RxjhServer
{
	public class MoveVector
	{
		private float destX;

		private float destY;

		private float destZ;

		private float fromX;

		private float fromY;

		private float fromZ;

		private float reach;

		private float speed;

		private DateTime timestamp;

		public MoveVector(Players Play, float x, float y, float z)
		{
			this.timestamp = DateTime.Now;
			this.destX = x;
			this.destY = y;
			this.destZ = z;
			this.fromX = Play.人物坐标_X;
			this.fromY = Play.人物坐标_Y;
			this.fromZ = Play.人物坐标_Z;
			this.speed = Play.Speed;
			float num = x - Play.人物坐标_X;
			float num2 = y - Play.人物坐标_Y;
			float num3 = (float)Math.Sqrt((double)(num * num + num2 * num2));
			this.reach = num3 / (Play.Speed / 1000f);
		}

		public MoveVector(Players Play, float x, float y, float z, float fromx, float fromy, float fromz)
		{
			this.timestamp = DateTime.Now;
			this.destX = x;
			this.destY = y;
			this.destZ = z;
			this.fromX = fromx;
			this.fromY = fromy;
			this.fromZ = fromz;
			this.speed = Play.Speed;
			float num = x - Play.人物坐标_X;
			float num2 = y - Play.人物坐标_Y;
			float num3 = (float)Math.Sqrt((double)(num * num + num2 * num2));
			this.reach = num3 / (Play.Speed / 1000f);
		}

		public void Get(out float x, out float y, out float z)
		{
			float num = (float)DateTime.Now.Subtract(this.timestamp).TotalMilliseconds / this.reach;
			if (this.reach == 15f || num > 31f)
			{
				x = this.destX;
				y = this.destY;
				z = this.destZ;
				return;
			}
			float num2 = this.destX - this.fromX;
			float num3 = this.destY - this.fromY;
			float num4 = this.destZ - this.fromZ;
			num2 *= num;
			num3 *= num;
			num4 *= num;
			x = this.fromX + num2;
			y = this.fromY + num3;
			z = this.fromZ + num4;
		}

		public bool NearDestination()
		{
			float num = (float)DateTime.Now.Subtract(this.timestamp).TotalMilliseconds - this.reach;
			return num < 1000f;
		}

		public bool ReachDestination()
		{
			float num = (float)DateTime.Now.Subtract(this.timestamp).TotalMilliseconds / this.reach;
			return num > 1f || this.reach == 0f;
		}

		public void Update(float x, float y, float z, float speed)
		{
			this.Get(out this.fromX, out this.fromY, out this.fromZ);
			this.timestamp = DateTime.Now;
			float num = x - this.fromX;
			float num2 = y - this.fromY;
			this.destX = x;
			this.destY = y;
			this.destZ = z;
			float num3 = (float)Math.Sqrt((double)(num * num + num2 * num2));
			this.reach = num3 / (speed / 1000f);
		}
	}
}
